using Amazon.Auth.AccessControlPolicy;
using Amazon.SecurityToken.Model;
using EmitMapper;
using Mapster;

namespace XjjXmm.Infrastructure.Mapper
{
	public static class EmitMapperExtension
	{
		/// <summary>
		/// 对象映射
		/// </summary>
		/// <typeparam name="S">源类型</typeparam>
		/// <typeparam name="T">目标类型</typeparam>
		/// <returns>映射结果</returns>
		public static T? MapTo<S, T>(this S source)
		{
            if (source == null) return default;

            var dest = source.Adapt<S, T>();
            //var mapper = ObjectMapperManager.DefaultInstance.GetMapper<S, T>();
            //var result = mapper.Map(source);
            return dest;
		}


		/// <summary>
		/// 对象列表映射
		/// </summary>
		/// <typeparam name="S">源类型</typeparam>
		/// <typeparam name="T">目标类型</typeparam>
		/// <returns>映射结果</returns>
		public static IEnumerable<T>? MapTo<S, T>(this IEnumerable<S> sources)
		{
			if (sources == null) return default;

            var dest = sources.Adapt<IEnumerable<S>, IEnumerable<T>>();
            return dest;
            //var mapper = ObjectMapperManager.DefaultInstance.GetMapper<S, T>();
            //return mapper.MapEnum(sources);
        }

        /// <summary>
        /// 对象映射
        /// </summary>
        /// <typeparam name="S">源类型</typeparam>
        /// <typeparam name="T">目标类型</typeparam>
        /// <returns>映射结果</returns>
        public static T? MergeTo<S, T>(this S source, T target)
        {
            if (source == null) return target;

            var dest = source.Adapt<S, T>(target);
            //var mapper = ObjectMapperManager.DefaultInstance.GetMapper<S, T>();
            //var result = mapper.Map(source);
            return dest;
        }
    }
}
